package com.rock.sys.controller;

import com.eova.aop.AopContext;
import com.eova.aop.MetaObjectIntercept;
import com.eova.common.utils.xx;
import com.eova.model.MetaObject;
import com.eova.service.sm;
import com.eova.template.common.util.TemplateUtil;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

public class RockFormController extends Controller {

	/**
	 * 通用文档预览
	 * 
	 * @throws Exception
	 */
	public void docView() throws Exception {
		AopContext ac = new AopContext(this);

		String objectCode = this.getPara(0);
		// 获取主键的值
		Object pkValue = getPara(1);
		
		MetaObject object = sm.meta.getMeta(objectCode);

		// 根据主键获取对象
		Record record = null;
		if(!xx.isEmpty(pkValue))
		 record = Db.use(object.getDs()).findById(object.getView(), object.getPk(), pkValue);
		
		if(record == null){
			setAttr("model", true);
			record = new Record();
		}
			
		setAttr("record", record);
		setAttr("object", object);

		ac.object = object;
		ac.record = record;
		
		MetaObjectIntercept intercept = TemplateUtil.initMetaObjectIntercept(object.getBizIntercept());
//		if (intercept != null) {
//			String msg = intercept.detailAfter(ac);
//			if (!xx.isEmpty(msg)) {
//				renderJson(new Response(Response.STATUS_FAIL,"文档查看后置拦截执行异常!" + msg));
//				return;
//			}
//		}


		ac.record.set("name", "陆家嘴软件园");
		ac.record.set("img1", "http://static.rockits.top/img/t_onform_images/image1/1605536584255.jpg");
		ac.record.set("img2", "http://static.rockits.top/img/t_onform_images/image1/1605536584255.jpg");
		render("/rock/template/single/doc.html");
	}
}
